# -*- coding:utf-8 -*-
from protocol import *
from twisted.internet.protocol import ClientFactory
from API import *

cmd = Command()
config = MyJson(filename='config.json')
if __name__ == '__main__':
    # log.write('Json file loading')
    # js = MyJson("json_test.json")
    # log.write("success")
    # from twisted.internet import reactor
    #
    # if js.get_cmd() == cmd.DOWNLOAD:
    #     class run_file_tran(ClientFactory):
    #         def __init__(self):
    #             self.serverpath = js.get_server_file()
    #             self.localpath = js.get_client_file()
    #
    #         def buildProtocol(self, addr):
    #             return FileTranClientProtocol(self.serverpath, self.localpath)
    #
    #
    #     def GetFile():
    #         f = run_file_tran()
    #         reactor.connectTCP(js.get_address()[0], js.get_address()[1], f)
    #
    #
    #     log.write("Downloading " + js.get_server_file())
    #     GetFile()
    #     reactor.run()
    #     log.write("success")
    # elif js.get_cmd() == cmd.UPLOAD:
    #     class run_file_tran(ClientFactory):
    #         def __init__(self):
    #             self.serverpath = js.get_server_file()
    #             self.localpath = js.get_client_file()
    #
    #         def buildProtocol(self, addr):
    #             return FileTranUploadProtocol(self.serverpath, self.localpath)
    #
    #
    #     def GetFile():
    #         f = run_file_tran()
    #         reactor.connectTCP(js.get_address()[0], js.get_address()[1], f)
    #
    #
    #     log.write("Uploading to" + js.get_server_file())
    #     GetFile()
    #     reactor.run()
    #     log.write("success")

    ui = MyJson(filename='create_user' + ".json")


    class Tmp(ClientFactory):
        def buildProtocol(self, addr):
            return CCP(ui.object)


    from twisted.internet import reactor

    f = Tmp()
    reactor.connectTCP(config.object['test']['host'], config.object['test']['port'], f)
    reactor.run()
